home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.4)
-
- from test.test_support import verbose, TestFailed, TestSkipped, verify
- import sys
- import os
- from unicodedata import normalize
- TESTDATAFILE = 'NormalizationTest-3.2.0' + os.extsep + 'txt'
- for path in [
- os.path.curdir,
- os.path.pardir]:
- fn = os.path.join(path, TESTDATAFILE)
- skip_expected = not os.path.exists(fn)
- if not skip_expected:
- TESTDATAFILE = fn
- break
- continue
-
-
- class RangeError:
- pass
-
-
- def NFC(str):
- return normalize('NFC', str)
-
-
- def NFKC(str):
- return normalize('NFKC', str)
-
-
- def NFD(str):
- return normalize('NFD', str)
-
-
- def NFKD(str):
- return normalize('NFKD', str)
-
-
- def unistr(data):
- data = [ int(x, 16) for x in data.split(' ') ]
- for x in data:
- if x > sys.maxunicode:
- raise RangeError
- continue
- []
-
- return []([ unichr(x) for x in data ])
-
-
- def test_main():
- if skip_expected:
- raise TestSkipped(TESTDATAFILE + ' not found, download from ' + 'http://www.unicode.org/Public/3.2-Update/' + TESTDATAFILE)
-
- part1_data = { }
- for line in open(TESTDATAFILE):
- if '#' in line:
- line = line.split('#')[0]
-
- line = line.strip()
- if not line:
- continue
-
- if line.startswith('@Part'):
- part = line
- continue
-
-
- try:
- (c1, c2, c3, c4, c5) = [ unistr(x) for x in line.split(';')[:-1] ]
- except RangeError:
- continue
-
- if verbose:
- print line
-
- None(verify if NFC(c1) == NFC(c1) and NFC(c2) == NFC(c2) else NFC(c2) == NFC(c3), line)
- None(verify if NFC(c4) == NFC(c4) else NFC(c4) == NFC(c5), line)
- None(verify if NFD(c1) == NFD(c1) and NFD(c2) == NFD(c2) else NFD(c2) == NFD(c3), line)
- None(verify if NFD(c4) == NFD(c4) else NFD(c4) == NFD(c5), line)
- c4(NFKC(c1) if NFKC(c1) == NFKC(c1) and NFKC(c2) == NFKC(c2) and NFKC(c3) == NFKC(c3) and NFKC(c4) == NFKC(c4) else NFKC(c4) == NFKC(c5), line)
- c5(NFKD(c1) if NFKD(c1) == NFKD(c1) and NFKD(c2) == NFKD(c2) and NFKD(c3) == NFKD(c3) and NFKD(c4) == NFKD(c4) else NFKD(c4) == NFKD(c5), line)
- if part == '@Part1':
- part1_data[c1] = 1
- continue
- verify
-
- for c in range(sys.maxunicode + 1):
- X = unichr(c)
- if X in part1_data:
- continue
-
- if NFC(X) == NFC(X) and NFD(X) == NFD(X) and NFKC(X) == NFKC(X):
- pass
- elif not NFKC(X) == NFKD(X):
- raise AssertionError, c
- X
-
- normalize('NFC', u'한글')
-
- if __name__ == '__main__':
- test_main()
-
-